package edu.kit.csl.cratyli.control;

import edu.kit.csl.cratyli.ui.Configuration;

/**
 * Implementing classes control the annealing process of weights in the primary
 * corpus relative to the weights in the secondary corpus. 
 */
public abstract class AnnealingFunction {
	/**
	 * Total number of secondary corpora.
	 */
	protected final int total;
	/**
	 * Current secondary corpus.
	 */
	protected int cur;
	/**
	 * cur/total.
	 */
	protected double progress;
	/**
	 * The temperature when cur = 1.
	 */
	protected double startTemperature;
	/**
	 * The temperature when cur = total
	 */
	protected double endTemperature;
	
	/**
	 * Sole constructor. Initializes the total, cur, and progress parameters
	 * according the secondaryCratylusPaths parameters. 
	 */
	public AnnealingFunction() {
		Configuration conf = Configuration.getSingleton();
		cur = 0;
		progress = 0;
		total = conf.getString("secondaryCratylusPaths").trim()
				.split(" ").length;
		startTemperature = conf.getFloat("startTemperature");
		endTemperature = conf.getFloat("endTemperature");
	}
	
	/**
	 * Increments the cur variable and adjusts progress accordingly. This
	 * function should be called whenever a new secondary corpus is selected
	 * for merging.
	 */
	public void next() {
		if (cur < total) {
			cur++;
			progress = 1.0 * cur / total;
		}
	}
	
	/**
	 * Calculates the current weight for the primary words, given the current
	 * value of progress.
	 */
	abstract public double getTemperature();
}
